/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package sharefileserver;

import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.UnknownHostException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author awsdh
 */
public class ConsoleMain {
    public static void main(String[] args) {
        InetAddress addr = null;
        try {
            addr = InetAddress.getLocalHost();
        } catch (UnknownHostException ex) {
            Logger.getLogger(ServerGUI.class.getName()).log(Level.SEVERE, null, ex);
        }
        String ipAddr = addr.getHostAddress();
        System.out.println("   Server is running...\nIP: "+ipAddr);
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    // TODO code application logic here
                    //crate registry port to client can connect
                    RMIServer server = new RMIServer();
                    LocateRegistry.createRegistry(1080);
                    String url = "rmi://localhost:1080/Shareserver";
                    //binding server handler with url
                    Naming.rebind(url, server);
                    System.out.println("Server is running.....");
                } catch (MalformedURLException | RemoteException ex) {
                    Logger.getLogger(RMIServer.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }).start();
    }
}
